/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved.
 *
 */

import path from 'path';

import { AbilityTypeEnum } from '../../enum/ability-type-enum';
import { CodeType } from '../../enum/code-type-enum';
import { ConfigJson } from '../../options/configure/config-json-options';

import { LegacyAbilityModel } from './legacy-ability-model';

export class LegacyWorkerModelImpl implements LegacyAbilityModel {
  private readonly workerFilePath: string | undefined;

  constructor(workerConfig: string[]) {
    if (workerConfig.length > 0) {
      this.workerFilePath = workerConfig[0];
    }
  }

  getConfigJsonJsObj(): ConfigJson.JsObj | undefined {
    return undefined;
  }

  getName(): string {
    if (!this.workerFilePath) {
      return '';
    }
    return path.basename(this.workerFilePath, path.extname(this.workerFilePath));
  }

  getRelateSrcPath(): string {
    if (!this.workerFilePath) {
      return '';
    }
    return path.basename(path.dirname(this.workerFilePath));
  }

  getSrcLanguage(): CodeType {
    return CodeType.ETS;
  }

  getType(): AbilityTypeEnum {
    return AbilityTypeEnum.WORKER;
  }
}
